import uuid from 'uuid';
import query from './atom/db/query';
import insert from './atom/db/insert';
import { IBaseTable } from './atom/db/interfaces';

declare const action_id: string;
declare const session_id: string;
declare const spaceid: string;

interface Message {
	staff_name: string,
	sex: string,
	id_no: string,
	birthday: string,
	age: number,
	native_place: string,
	zodiac: string,
	blood_type: string,
	f_name: string,
	marital_status: string,
	politics_face: string,
	entry_party_time: string,
	reg_per_res: string,
	education: string,
	bachelo_ocience: string,
	staff_picture: string,
	accessory_url: string,
	province: string,
	staff_type: string,
	deptid: string,
	_id?: string,
	deptname?: string,
	staff_number?: string,
	staff_job_status?: string
}
async function atom(msg: Message) {
	const systemid = '6051';
	const { exec: e1, prepare: p1 } = query(action_id, session_id, spaceid, systemid);
	p1('dept', ['deptname'], { deptid: msg.deptid }, 1);
	const [depts] = await e1();
	const { exec, prepare } = insert(action_id, session_id, spaceid, systemid);
	prepare('teach_staff', [Object.assign({ _id: uuid(), deptname: depts[0]['deptname'], staff_number: uuid(), staff_job_status: '1' }, msg)]);
	const res = await exec();
	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}